<?php

/*

User Profile (user_profile.php)

*/

$rank_check = 1;
$page_title = "User Profile";
include "header.inc.php";

$members = fetch("SELECT * FROM members2 WHERE username = '$user' AND game = '$game'");
$members_profiles = fetch("SELECT * FROM members_profiles2 WHERE username = '$user' AND game = '$game'");

$online = fetch("SELECT last_visit FROM online WHERE userid = '$members[id]' ORDER BY last_visit DESC LIMIT 1");

if ($rank == "7")
{
	$iplog = fetch("SELECT ip_addr FROM ip_log WHERE userid = '$members[id]' ORDER BY id DESC LIMIT 1");
	$membersIP = " ($iplog[ip_addr])";
}
if (!$members[id])
{
	die("$openHTML<p align=center class=error>That is not a real user</p>$closeHTML");
}

if ($members[rank] <= 1)
{
	die("$openHTML<p align=center class=error>This user has been suspended.</p>$closeHTML");
}

$gender = $members_profiles[gender];
$genderArray = array("<img src=images/icons/undecided.gif>", "<img src=images/icons/female.gif>", "<img src=images/icons/male.gif>");
$gender = $genderArray[$gender];

$mailSettings = $members_profiles[mail_settings];
$mailSettingsArray = array(
"<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>",
"<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>",
"");
$mailSettings = $mailSettingsArray[$mailSettings];

$bud = "<a href=buds.php?game=$game&bud=$members[username]><img src=images/icons/bud.gif></a>";

$date_registered = date("M j, Y", $members_profiles[date_registered]);
$last_visited = date("H:i", $online[last_visit]);
$last_visited2 = date("M j, Y @ H:i", $online[last_visit]);

$exBday = explode("-", $members_profiles[birthday]);

$months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "Septemeber", "October", "November", "December");

$bdayMonth = $exBday[0];
if ($bdayMonth < 10) { $bdayMonth = ereg_replace("0", "", $bdayMonth); }

$exBday[0] = $months[$bdayMonth];

$birthday = "$exBday[0] $exBday[1], $exBday[2]";

$userAge = $this_year - $exBday[2];
if ($this_month < $exBday[0])
{
	$userAge = $userAge - 1;
}
if (($this_month == $exBday[0]) AND ($today < $exBday[1]))
{
	$userAge = $userAge - 1;
}

if ($online[last_visit] >= ($timestamp - $secondsToKeepUsersOn))
{
	$onlineNow = "<b><font color=green>Yes! <i><font size=-1>last visit at $last_visited</font></i></font></b>";
}
else
{
	$onlineNow = "<B><font color=red>No <i><font size=-1>last visit on $last_visited2</font></i></font></b></font></b>";
}

$yourNotes = fetch("SELECT bud_note FROM buds2 WHERE bud_me = '$userid' AND bud_you = '$members[id]'");
$yourNotes = $yourNotes[bud_note];
if (!$yourNotes) { $yourNotes = "<i>You do not have any notes on the player, add them to your buddy list to add notes!</i>"; }

$find_shop = fetch("SELECT shop_name,shop_size FROM usershops2 WHERE owner = '$members[id]' AND game = '$game'");
if ($find_shop[shop_name])
{
	$usershop_line = "<b>Shop:</b> <a href=$base_url/usershop.php?game=$game&user=$user>$find_shop[shop_name]</a> <font size=-1>(size $find_shop[shop_size])</font>";
}

$find_gallery = fetch("SELECT gallery_name,gallery_size FROM usergallerys WHERE owner = '$members[id]' AND game = '$game'");
if ($find_gallery[gallery_name])
{
	$gallery_line = "<br><b>Gallery:</b> <a href=$base_url/usergallery.php?game=$game&user=$user>$find_gallery[gallery_name]</a> <font size=-1>(size $find_gallery[gallery_size])</font>";
}

$locationLine = $members_profiles[location];
if (!$locationLine)
{
	$locationLine = "<i>Middle of no where!</i>";
}

$getClub = fetch("SELECT position,club FROM club_members2 WHERE user = '$members[id]' AND game = '$game'");
$getclub = fetch("SELECT id,name FROM clubs2 WHERE id = '$getClub[club]' AND game = '$game'");
if ($getclub[id])
{
	$clubrank = $getClub[position];
	if ($clubrank == 1)
	{
		$position = "Member";
	}
	if ($clubrank == 2)
	{
		$position = "Moderator";
	}
	if ($clubrank == 3)
	{
		$position = "Admin";
	}
	$club_line = "<br><b>Club:</b> $position in <a href=$base_url/club.php?game=$game&clubid=$getclub[id]>$getclub[name]</a>";
}


$findPets = mysql_query("SELECT id,name,level FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = '$game'");
$numUserPets = mysql_num_rows($findPets);
$x = 1;
while ($getPets = mysql_fetch_array($findPets))
{
	if ($x < $numUserPets)
	{
		$petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level]), ";
	}
	else
	{
		$petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level])";
	}
	$x++;
}

echo <<<END
$openHTML

<table bgcolor=#ffffff width=95%>
<tr><td>
         <CENTER><FONT SIZE="+2"><B>--$members[display_name]'s Profile--</B></FONT></CENTER>

         <p>$members_profiles[profile]</p>

         <center><hr width=75% color="$tableOutline"></center>

         <font size=-1>

         <P><b>Username:</b> $members[display_name]$membersIP<br>
			<b>Real name:</b> $members_profiles[real_name]<bR>
			<b>Birthday:</b> $birthday ($userAge years old!)<br>
			<b>Location:</b> $locationLine<br>
			<b>Date Registered:</b> $date_registered<br>
			<b>Total Referrals:</b> $members_profiles[referrals]<br>
            <b>Total Posts:</b> $members[post_count]
         </P>

         <P><b>Your Notes:</b> $yourNotes</P>

         <P><b>$numUserPets Pets:</b> $petList</p>

         <P>$usershop_line<br>
         $club_line
         $gallery_line</p>

         <p><b>Online?</b> $onlineNow</P>

	 	 </font>

<center><table><tr><td>
<form action=mail_send.php?game=$game&send_to=$members[username] method=post>
<input type=submit value="Send Mail">
</form></td><td>
<form action=buds.php?game=$game&bud=$members[username] method=post>
<input type=submit value="Add to Buddy List">
</form></td></tr></table></center>
</td></tr></table>

$closeHTML
END;

?>